---
title: Ckan
sidebarTitle: Ckan
---

This is the implementation of the Ckan data handler for MindsDB.

[CKAN](https://ckan.org/) is a Data Catalogue for Open Data. It stores data in a [DataStore](http://docs.ckan.org/en/2.9/maintaining/datastore.html). To retrieve data from CKAN, you need to use the [CKAN API](https://ckan.org/docs/api/). 

## Prerequisites

Before proceeding, ensure the following prerequisites are met:

1. Install MindsDB [locally via Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or use [MindsDB Cloud](https://cloud.mindsdb.com/).
2. To connect Ckan to MindsDB, install the required dependencies following [this instruction](/setup/self-hosted/docker#install-dependencies).
3. Install or ensure access to Ckan.

## Implementation

You can connect CKAN by creating a CKAN API client. In this handler, you can create a CKAN API client with [ckanapi](https://github.com/ckan/ckanapi).

<Info>
Some CKAN instances require you to provide API key. You can find it in the CKAN user panel.
</Info>

```python
from ckanapi import RemoteCKAN
ckan = RemoteCKAN('https://ckan.example.com/', apikey='YOUR_API_KEY')
```

CKAN API client supports all API methods of CKAN. For our handler we use the [DataStore API](http://docs.ckan.org/en/2.9/maintaining/datastore.html#the-datastore-api).

The [`datastore_search_sql` ](http://docs.ckan.org/en/2.9/maintaining/datastore.html#ckanext.datastore.logic.action.datastore_search_sql) action supports raw SQL commands to be used to search for the data.

Here is an example:

```python
ckan.action.datastore_search_sql(sql='SELECT * FROM "resource_id"')
```

## Usage

In order to make use of this handler and connect to a Ckan server in MindsDB, the following syntax can be used:

```sql
CREATE DATABASE ckan_datasource
WITH
  engine = 'ckan',
  parameters = {
    "url": "http://demo.ckan.org/api/3/action/",
    "apikey": "YOUR_API_KEY"
  };
```
